#include "login.h"
#include "ui_login.h"
#include "lib/sql.h"
#include <QMessageBox>

login::login(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::login)
{
    ui->setupUi(this);

}

login::~login()
{
    delete ui;
}


void login::on_pushButton_clicked()
{
     //登录
     if (fla == 1){
         auto ret=Sql::getinstance()->login_user(ui->login_acount->text(),ui->login_pass->text());
         if(ret)
         {
             setResult(1);
             hide();
         }
         else
         {
             setResult(0);
             QMessageBox::information(nullptr,"信息","用户名或者密码错误");
         }
     }
     else if(fla == 2)
     {
         auto ret=Sql::getinstance()->login_master(ui->login_acount->text(),ui->login_pass->text());
         if(ret)
         {
             setResult(1);
             hide();
         }
         else
         {
             setResult(0);
             QMessageBox::information(nullptr,"信息","用户名或者密码错误");
         }
     }
     else{
         QMessageBox::information(nullptr,"信息","用户名或者密码错误");
         ui->login_acount->clear();
         ui->login_pass->clear();
     }

}


void login::on_pushButton_2_clicked()
{
    //退出
    setResult(0);
       hide();
}



void login::on_checkBox_stateChanged(int arg1)
{
    bool status =ui->checkBox->isChecked();

    if(status == true)
    {
        fla = 2;
    }
}

void login::on_checkBox_user_stateChanged(int arg1)
{
    bool status =ui->checkBox_user->isChecked();

    if(status == true)
    {
        fla = 1;
    }
}

